#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
def help():
	print '''
Index
>>> from cnlstk import index

Search
>>> from cnlstk import search
'''
"""

class use:

	def __init__( self, text ):
		self.text = text
		self.__index( self.text )

	def __index( self, text ):
		from cnlstk import index
		from cnlstk.index import suffixarray
		suffixarray.indexSA( text )

	def getConcordance( self, string, lb="", fb="forward"):
		from cnlstk import search
		from cnlstk.search import Search
		path = self.text.decode('utf8')
		line = string.decode('utf8')
		if fb == "forward":
			Fobj = Search('./Parsed_Text/%s/Text_f' % path , 'sch', './Parsed_Text/%s/Text_f_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		elif fb == "backward":
			Fobj = Search('./Parsed_Text/%s/Text_f' % path , 'schbk', './Parsed_Text/%s/Text_b_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		if lb != "":
			Fobj.setFilter( lb )
		rst = Fobj.getConcordance( line )
		for k in rst:
			print k[0], k[1]

	def getWordCount( self, string, lb=""):
		from cnlstk import search
		from cnlstk.search import Search
		path = self.text.decode('utf8')
		line = string.decode('utf8')
		Fobj = Search('./Parsed_Text/%s/Text_f' % path , 'sch', './Parsed_Text/%s/Text_f_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		if lb != "":
			Fobj.setFilter( lb )
		rst = Fobj.getConcordance( line )
		print "WordCount: %s " % len(rst)
		
	def getNextWords( self, string, word="1"):
		from cnlstk import search
		from cnlstk.search import Search
		path = self.text.decode('utf8')
		line = string.decode('utf8')
		Fobj = Search('./Parsed_Text/%s/Text_f' % path , 'sch', './Parsed_Text/%s/Text_f_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		rst = Fobj.getNextWords( line, int(word) )
		for k in rst:
			print k[0], k[1]
		
	def getNextWordCounts( self, string ):
		from cnlstk import search
		from cnlstk.search import Search
		path = self.text.decode('utf8')
		line = string.decode('utf8')
		Fobj = Search('./Parsed_Text/%s/Text_f' % path , 'sch', './Parsed_Text/%s/Text_f_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		rst = Fobj.getNextWordCounts( line )
		print rst
		
	def getPreWords( self, string, word="1"):
		from cnlstk import search
		from cnlstk.search import Search
		path = self.text.decode('utf8')
		line = string.decode('utf8')
		Bobj = Search('./Parsed_Text/%s/Text_f' % path , 'schbk', './Parsed_Text/%s/Text_b_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		rst = Bobj.getNextWords( line, int(word) )
		for k in rst:
			print k[0], k[1]
		
	def getPreWordCounts( self, string ):
		from cnlstk import search
		from cnlstk.search import Search
		path = self.text.decode('utf8')
		line = string.decode('utf8')
		Bobj = Search('./Parsed_Text/%s/Text_f' % path , 'schbk', './Parsed_Text/%s/Text_b_SA' % path , './Parsed_Text/%s/Text_lb' % path)
		rst = Bobj.getNextWordCounts( line )
		print rst
	
	